package regex;

import javax.swing.*;
import java.util.ArrayList;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
//使用正则爬取数据
public class PatternTest {
    public static void main(String[] args) {
        String data="电话:15009621591,15121829910,"+
                "邮箱:1534009229@qq.com,b1531009229@gmile.com.us"+
                "热线电话:400-820-8820,4407395784";
        String regex="[1][3-9]\\d{9}|\\w+[@][\\w&&[^_]]+(\\.[\\w&&[^_]]{2,3})+|[4]\\d{2}-?\\d{3}-?\\d{4}";
        //将正则表达式封装为对象
        Pattern pattern=Pattern.compile(regex);
        //把比较的数据封装为对象
        Matcher matcher = pattern.matcher(data);
        ArrayList<String>arrayList=new ArrayList<>();
        //通过循环,将找到的数据提取出来
        while ( matcher.find()){
            String groups = matcher.group();
            //System.out.println(groups);
            arrayList.add(groups);
        }
        for (int i = 0; i <arrayList.size() ; i++) {
            System.out.println( arrayList.get(i));
        }

    }
}
